<div class="row wrapper border-bottom white-bg page-heading">
    <div class="col-md-6">
        <h2>添加宝贝</h2>
        <ol class="breadcrumb">
            <li>
                <a href="index.html">主页</a>
            </li>
            <li class="active">
                <strong>添加宝贝</strong>
            </li>
        </ol>
    </div>
    <div class="col-md-6">
    </div>
</div>


<div class="wrapper wrapper-content">
    <div class="ibox float-e-margins">
        <div class="ibox-title">
            <h5>添加宝贝</h5>
            <div class="ibox-tools">
                <a class="collapse-link">
                    <i class="fa fa-chevron-up"></i>
                </a>
                <a class="dropdown-toggle" data-toggle="dropdown" href="#">
                    <i class="fa fa-wrench"></i>
                </a>
                <ul class="dropdown-menu dropdown-user">
                    <li><a href="#">Config option 1</a>
                    </li>
                    <li><a href="#">Config option 2</a>
                    </li>
                </ul>
                <a class="close-link">
                    <i class="fa fa-times"></i>
                </a>
            </div>
        </div>
        <div class="ibox">
            <div class="ibox-content">
                <form action="{:U('admin/product/do_add')}" method="post" class="form-horizontal">
                    <div class="form-group"><label class="col-sm-2 control-label">宝贝名称：</label>
                        <div class="col-sm-8"><input type="text" name="title" class="form-control"></div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                    <label class="col-sm-2 control-label">宝贝分类：</label>
                        <div class="col-sm-2">
                            <select id="level1" class="form-control">
                                <volist name="level1" id="l1">
                                    <option value="{$l1.id}">{$l1.name}</option>
                                </volist>
                            </select>
                        </div>
                        <div  class="col-sm-2">
                            <select id="level2" name="cata_id" class="form-control">
                            </select>
                        </div>
                        <div  class="col-sm-2">
                            <select id="level3" class="form-control">
                            </select>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                        <label class="col-sm-2 control-label">图片：</label>
                            <div class="col-sm-4"><input id="img" type="text" name="img" class="form-control"></div>
                            <div class="col-sm-2"><a href="#" id="upload" class="btn btn-info">上传</a></div>
                            <div class="col-sm-4">
                                <div id="preview"></div>
                            </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group">
                            <label class="col-sm-2 control-label">宝贝价格：</label>
                            <div class="col-sm-3"><input type="text" name="price" class="form-control"></div>
                            <label class="col-sm-2 control-label">宝贝库存：</label>
                            <div class="col-sm-3"><input type="text" name="stock" class="form-control"></div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group"><label class="col-sm-2 control-label">宝贝描述：</label>
                        <div class="col-sm-8">
                            <textarea class="form-control" rows="3" type="text" name="desc"></textarea>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group"><label class="col-sm-2 control-label">宝贝详情：</label>
                        <div class="col-sm-8">
                            <textarea id="content" class="form-control" type="text" name="content"></textarea>
                        </div>
                    </div>
                    <div class="hr-line-dashed"></div>
                    <div class="form-group"> 
                        <div class="col-sm-2"></div>
                        <div class="col-sm-8">
                            <button class="btn btn-primary" >保存</button>
                        </div>
                    </div>
                </form>
            </div>
        </div>
    </div>
</div>
<script src="__PUBLIC__/admin/js/plugins/kindeditor/kindeditor-all-min.js"></script>
<script src="__PUBLIC__/admin/js/plugins/kindeditor/lang/zh-CN.js"></script>
<script src="__PUBLIC__/admin/js/plugins/jquery.upload.js"></script>
<script type="text/javascript">
   editor = KindEditor.create('#content', {
        allowFileManager : true
    });
    function level1Chagne(){
        var id = $('#level1').val();
        $.get("{:U('admin/product/getCatalog')}",{id:id},function(data){
            var str = "";
            for (var i = 0; i < data.length; i++) {
                str += '<option value="'+data[i].id+'">'+data[i].name+'</option>';
            }
            $('#level2').html(str);
            level2Chagne();
        })
    }
    function level2Chagne(){
        var id = $('#level2').val();
        $.get("{:U('admin/product/getCatalog')}",{id:id},function(data){
            var str = "";
            for (var i = 0; i < data.length; i++) {
                str += '<option value="'+data[i].id+'">'+data[i].name+'</option>';
            }
            $('#level3').html(str);
        })
    }
    $('#level1').change(level1Chagne);
    $('#level2').change(level2Chagne);
    level1Chagne();


   $("#upload").click(function(){
        $.upload({
            url: '{:U("admin/util/upload")}', 
            fileName: 'file', 
            dataType: 'text',
            onSend: function() {
                return true;
            },
            onComplate: function(data) {
                if(data.indexOf("upload") >=0 ){
                    $("#img").val(data);
                    $("#preview").html('<img style="height:80px;" src="__ROOT__'+data+'" />');
                }else{
                    alert(data);
                }
            }
        });
        return false;
    })
</script>